from lxml import etree
# import re
# def checkText(s):
    
def getXmlModel(frompath, topath):
    doc = etree.parse(frompath)
    docraw = doc.getroot()
    needstr = ""
    docraw.text = needstr

    # for i in docraw.iter():
    #     try:
    #         if i.tag.func_name != "Comment":
    #         # if type(i.tag) == 'str':
    #             continue
    #     except AttributeError as identifier:
    #         i.text = needstr
    #         for a in i.keys():
    #             i.set(a, "")
    
    for i in docraw.iter():
        try:
            if isinstance(i.tag,str):
                i.text = needstr
                for a in i.keys():
                    i.set(a, "")
        except AttributeError as identifier:
            continue
    with open(topath, 'w', encoding='utf-8') as f:
        f.write(etree.tostring(docraw, encoding='utf-8', pretty_print=True).decode('utf-8'))


if __name__ == "__main__":
    getXmlModel(r"F:\chen\pythonworkspace\PythonGithub\TestFile\EMR-PL-01新增个人身份注册-F.xml", r'F:\chen\pythonworkspace\PythonGithub\TestFile\model.xml')